package com.lxl.commons.mapper.impl;

import com.lxl.commons.mapper.IMapper;
import com.lxl.settings.entity.User;
import javax.servlet.jsp.jstl.sql.Result;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户的Result转化成List集合
 * @author 北上寻海
 */
public class UserMapperImpl implements IMapper {
    @Override
    public List<User> mapper(Result result) {
         List<User> list = new ArrayList<>();
         if(result.getRowCount()!=0){

             for (int i = 0 ;i<result.getRowCount();i++){
                 User user = new User();
                 user.setId((String)result.getRowsByIndex()[i][0]);
                 user.setUsername((String)result.getRowsByIndex()[i][1]);
                 user.setPassword((String)result.getRowsByIndex()[i][2]);
                 list.add(user);
             }
         }else {
             list = null;
         }
         return list;
    }
}
